//
//  KongWChooseView.m
//  LoveOfPet
//
//  Created by dllo on 15/11/23.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "KongWChooseView.h"
#define kHeight     [UIScreen mainScreen].bounds.size.height / 667
#define kWidth      [UIScreen mainScreen].bounds.size.width / 375
@interface KongWChooseView ()
@property (retain, nonatomic) UIButton *doctorBtn;

@property (retain, nonatomic) UIButton *hospitalBtn;

@property (retain, nonatomic) UIButton *illnessBtn;

@property (retain, nonatomic) UILabel *line1;

@property (retain, nonatomic) UILabel *line2;

@property (assign, nonatomic) CGRect leftBtnFrame;
@end

@implementation KongWChooseView

-(instancetype) initWithFrame:(CGRect)frame andsearchLeftBtnFrame:(CGRect)leftBtnFrame
{
    self = [super initWithFrame:frame];
    if (self) {
        _doctorBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _line1 = [[UILabel alloc] init];
        _hospitalBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _line2 = [[UILabel alloc] init];
        _illnessBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftBtnFrame = leftBtnFrame;
    }
    return self;
}

#pragma mark search动画操作
-(void)pushView
{
    [UIView animateWithDuration:0.1 animations:^{
        self.frame = CGRectMake(kWidth * 20, kHeight * 114, self.leftBtnFrame.size.width, self.leftBtnFrame.size.height * 3);
        
        
        self.doctorBtn.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height / 3);
        [self.doctorBtn setTitle:@"找医生" forState:UIControlStateNormal];
        [self.doctorBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self.doctorBtn addTarget:self action:@selector(doctorBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.doctorBtn];
        
        self.line1.frame = CGRectMake(self.doctorBtn.frame.origin.x, self.doctorBtn.frame.origin.y + self.doctorBtn.frame.size.height, self.doctorBtn.frame.size.width, 1);
        self.line1.backgroundColor = [UIColor grayColor];
        [self addSubview:self.line1];
        
        
        self.hospitalBtn.frame = CGRectMake(0, self.frame.size.height / 3, self.frame.size.width, self.frame.size.height / 3);
        [self.hospitalBtn setTitle:@"找医院" forState:UIControlStateNormal];
        [self.hospitalBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self.hospitalBtn addTarget:self action:@selector(hospitalBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.hospitalBtn];
        
        self.line2.frame = CGRectMake(self.hospitalBtn.frame.origin.x, self.hospitalBtn.frame.origin.y + self.hospitalBtn.frame.size.height, self.hospitalBtn.frame.size.width, 1);
        self.line2.backgroundColor = [UIColor grayColor];
        [self addSubview:self.line2];
        
        
        self.illnessBtn.frame = CGRectMake(0, self.frame.size.height / 3 * 2, self.frame.size.width, self.frame.size.height / 3);
        [self.illnessBtn setTitle:@"查疾病" forState:UIControlStateNormal];
        [self.illnessBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self.illnessBtn addTarget:self action:@selector(illnessBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.illnessBtn];
    }];
}
-(void)doctorBtnAction:(id)sender
{
    [self.delegate returnATitle:@"找医生"];
    [self backView];
    
}

-(void)hospitalBtnAction:(id)sender
{
    [self.delegate returnATitle:@"找医院"];
    [self backView];
    
}

-(void)illnessBtnAction:(id)sender
{
    [self.delegate returnATitle:@"查疾病"];
    [self backView];
    
}
-(void)backView
{
    [UIView animateWithDuration:0.1 animations:^{
        self.frame = CGRectMake(kWidth * 20, kHeight * 114, self.leftBtnFrame.size.width, 0);
        [self.doctorBtn removeFromSuperview];
        [self.line1 removeFromSuperview];
        [self.hospitalBtn removeFromSuperview];
        [self.line2 removeFromSuperview];
        [self.illnessBtn removeFromSuperview];
    }];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
